// +-------------------------------- DISCLAIMER ---------------------------------+
// |                                                                             |
// | This program is provided to you free of charge "as such".                   |
// | You should not assume that this program is error-free or suitable for any   |
// | purpose whatsoever.                                                         |
// |                                                                             |
// | EURESYS does not give any representation, warranty or undertaking that this |
// | program is free of any defect or error or suitable for any purpose. EURESYS |
// | shall not be liable, in contract, in torts or otherwise, for any damages,   |
// | loss, costs, expenses or other claims for compensation, including those     |
// | asserted by third parties, arising out of or in connection with the use of  |
// | this program.                                                               |
// +-----------------------------------------------------------------------------+

#ifndef CAMERAHANDLER_H
#define CAMERAHANDLER_H

#include <string>
#include <atomic>
#include <condition_variable>
#include <memory>
#include <thread>
#include <vector>

#include "CameraDefine.h"

#include "EasyImage.h"

using namespace Euresys::Open_eVision;

class CameraHandler
{
public:
  CameraHandler();
  ~CameraHandler();
  void launchCamera();
  void run();
  void stop();

  void getImage(EImageBW8& image);
  bool isAborted();

  void setExposureModeManual(int analogGain = 2, double exposureTime = 6000);

private:
  std::mutex processImageMutex_;
  std::condition_variable canProcessImage_;

  uint8_t* data_;
  uint32_t width_;
  uint32_t height_;
  uint32_t pitch_;
  std::atomic<bool> abort_;

  std::thread cameraThread_;
  std::unique_ptr<EImageBW8> image_;

  int init_SDK();

  int                     camera_;
  tSdkCameraCapbility     tCapability;


  // make non-copyable
  CameraHandler( const CameraHandler& );
  CameraHandler& operator=( const CameraHandler& );
};

#endif // CAMERAHANDLER_H


